package com.chukun.netty.websocket;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;

/**
 * @author chukun
 * 初始化服务端的解码器
 */
public class NettyWebSocketChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //换行符解码器
        ch.pipeline().addLast("http server codec",new HttpServerCodec());
        ch.pipeline().addLast("http aggregator",new HttpObjectAggregator(8192));
        ch.pipeline().addLast("web socket",new WebSocketServerProtocolHandler("/ws"));
        ch.pipeline().addLast("client chat handler",new NettyWebSocketServerHandler());
    }
}
